let x=1101;
console.log(reverse(x));


function reverse(x: number): number {
    if(x===0)
        return x;
    let result:number =0;
    let flag=Math.sign(x);
    x=Math.abs(x)
    while(x%10===0){
        x=x/10
    }
    while(x!==0){
        result=result*10+x%10;
        x=Math.floor(x/10);
    }
    if(result*flag>=Math.pow(2,31)||result*flag<=(-1*Math.pow(2,31)))
        return 0;
    return result*flag;
};